import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;

class P790_39643 {

    private static Hashtable teams;
	private static Vector teamsVector;
	private static int largestTeamID;

	public static void main(String[] args) {
    	int cases = Integer.parseInt(readLn());
    	
    	readLn();
    	
    	for (int k = 0; k < cases; k++) { 
    		process();
    		if (k + 1 != cases) System.out.println();
    	}
    }

	private static void process() {
		teams = new Hashtable();
		teamsVector = new Vector();
		String line = readLn();
		largestTeamID = 0;
		
		while (line != null && !"".equals(line)) {
			readTeams(line);
			
			line = readLn();
		}
		
		addMoreTeams();
		
		
		
		sort();
		
//		System.out.println(teamsVector);
		
		print();
	}

	private static void addMoreTeams() {
		for (int k = 1; k <= largestTeamID; k++) {
			Integer teamNo = new Integer(k);
			OlympTeam team = (OlympTeam) teams.get(teamNo);
			
			if (team == null) {
				team = new OlympTeam();
				team.id = teamNo.intValue();
				teams.put(teamNo, team);
				teamsVector.addElement(team);
				
			} else {
				
				team.computeSubmissions();
			}
			
		}
		
	}

	private static void print() {
		
		int length = teamsVector.size();
		int[] rank = new int[length];
		
		int rankNo = 1;
		if (length > 0) rank[0]= 1;
		
		for (int k = 1; k < length; k++) {
			rankNo++;
			OlympTeam a = (OlympTeam) teamsVector.elementAt(k);
			OlympTeam b = (OlympTeam) teamsVector.elementAt(k-1);
			if (a.compareToPoints(b) == 0) {
				rank[k] = rank[k-1];
			} else {
				rank[k] = rankNo;
			}
			
		}
		
//		for (int k = 0; k < rank.length; k++) {
//			System.out.println(rank[k]);
//		}
		
		System.out.println("RANK TEAM PRO/SOLVED TIME");
		for (int k = 0; k < length; k++) {
			print(rank[k], (OlympTeam) teamsVector.elementAt(k));
		}
		
	}
//	RANK TEAM PRO/SOLVED TIME
//	   1    3    2        172
//	   2    1    1        100
//	   2    4    1        100
//	   4    2
	private static void print(int rank, OlympTeam team) {
		if (team.numberOfAccepted != 0)
			System.out.println(format(rank, 4) + format(team.id, 5) + format(team.numberOfAccepted, 5) + format(team.totalTime, 11));
		else {
			System.out.println(format(rank, 4) + format(team.id, 5));
		}
	}

	private static String format(int value, int spaces) {
		String valueStr =   Integer.toString(value);
		int length = valueStr.length();
		for (int k = spaces; k > length; k--) 
			valueStr = " " + valueStr;
		return valueStr;
	}

	private static void sort() {
		int length = teamsVector.size();
		for (int k = 0; k < length; k++) {
			for (int j = k + 1; j < length; j++) {
				OlympTeam a = (OlympTeam)teamsVector.elementAt(k);
				OlympTeam b = (OlympTeam)teamsVector.elementAt(j);
				if (a.compareTo(b) < 0) {
					swap(k, j);
				}
			}
		}
	}

	private static void swap(int k, int j) {
		Object o = teamsVector.elementAt(k);
		teamsVector.setElementAt(teamsVector.elementAt(j), k);
		teamsVector.setElementAt(o, j);
	}

	private static void readTeams(String line) {
		StringTokenizer st = new StringTokenizer(line);
		
		Integer teamNo = new Integer(st.nextToken());
		
		Submission submission = new Submission();
		submission.question = st.nextToken();
		
		StringTokenizer stTime = new StringTokenizer(st.nextToken(), ":");
		
		submission.hour = Integer.parseInt(stTime.nextToken());
		submission.minute = Integer.parseInt(stTime.nextToken());
		
		submission.accepted = st.nextToken().toLowerCase().equals("y");
		
		OlympTeam team = (OlympTeam) teams.get(teamNo);
		
		if (team == null) {
			team = new OlympTeam();
			team.id = teamNo.intValue();
			teams.put(teamNo, team);
			teamsVector.addElement(team);
			
			if (largestTeamID < team.id) largestTeamID = team.id;
		}
		
		team.logSubmission(submission);
		
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

}

class OlympTeam {
	
	int id;
	int totalTime = 0;
	
	private Hashtable submissions = new Hashtable();
	
	private Vector submissionsLog = new Vector();
	
	int numberOfAccepted = 0;
	
	public String toString() {
		return "Team: " + id + " accepted: " + numberOfAccepted + " total time:" + totalTime + " " + submissionsLog;
	}
	
	public int compareTo(OlympTeam b) {
		if (this.numberOfAccepted != b.numberOfAccepted) return this.numberOfAccepted - b.numberOfAccepted;
		if (this.totalTime != b.totalTime) return b.totalTime - this.totalTime;
		return b.id - this.id;
	}
	
	public int compareToPoints(OlympTeam b) {
		if (this.numberOfAccepted != b.numberOfAccepted) return this.numberOfAccepted - b.numberOfAccepted;
		return b.totalTime - this.totalTime;
	}

	public void computeSubmissions() {
		this.sortLog();
		
		for (int k = 0; k < submissionsLog.size(); k++) {
			addSubmission((Submission) submissionsLog.elementAt(k));
		}
	}
	
	public void logSubmission(Submission sub) {
		submissionsLog.addElement(sub);
	}
	
	private void sortLog() {
		int length = submissionsLog.size(); 
		for (int k = 0; k < length; k++) {
			for (int j = k + 1; j < length; j++) {
				Submission a = (Submission) submissionsLog.elementAt(k);
				Submission b = (Submission) submissionsLog.elementAt(j);
				if (a.compareTo(b) > 0) {
					swap(k, j);
				}
			}
		}
	}

	private void swap(int k, int j) {
		Object o = submissionsLog.elementAt(k);
		submissionsLog.setElementAt(submissionsLog.elementAt(j), k);
		submissionsLog.setElementAt(o, j);
	}

	
	private void addSubmission(Submission sub) {
		SubmissionRecord record = (SubmissionRecord) submissions.get(sub.question);
		
		if (record == null) {
			record = new SubmissionRecord();
			submissions.put(sub.question, record);
		}
		
		if (!record.accepted) {
			
			if (!sub.accepted) {
				record.amountTime += 20;
			} else {
				
				totalTime = totalTime + (sub.hour * 60) + (sub.minute) + record.amountTime;
				
				record.accepted = true;
			}
			
			if (record.accepted) numberOfAccepted++;
		}
	}
	
	public int getTotalTime() {
		return totalTime;
	}
	
}

class SubmissionRecord {
	
	int amountTime;
	
	boolean accepted;
	
	public String toString() {
		return "total time: " + amountTime + " accepted: " + accepted;
	}
	
}

class Submission {
	
	int hour;
	int minute;
	
	String question;
	
	boolean accepted;
	
	public String toString() {
		return "Submission: " + question + " (" + hour + ":" + minute + ") Accepted: " + accepted; 
	}

	public int compareTo(Submission b) {
		if (this.hour != b.hour) return this.hour - b.hour;
		if (this.minute != b.minute) return this.minute - b.minute;
		if (this.accepted && !b.accepted) return + 1;
		else if (!this.accepted && b.accepted) return -1;
		return 0;
	}
	
}